<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //  题目：实现一个函数，比较两个版本号的大小。返回 1（大于）/0（等于）/-1（小于）
        function compareVer(ver1, ver2) {
            // 代码写在这里↓↓↓↓↓
            ver1 = ver1.split('.')
            ver2 = ver2.split('.')

            let sameCount = 0
            for (let i = 0; i < ver1.length; i++) {
                if (parseInt(ver1[i]) > parseInt(ver2[i])) {
                    return 1
                } else if (parseInt(ver1[i]) == parseInt(ver2[i])) {
                    sameCount++
                } else return -1
            }
            if (sameCount === ver1.length) {
                return 0
            }

            // 代码写在这里↑↑↑↑↑
        }
        console.log(compareVer("2.0.1", "1.1.1")); // 2.0.1 < 1.1.1 返回 1
        console.log(compareVer("0.0.20", "1.0.3")); // 0.0.20 > 1.0.3 返回 -1
    </script>
</body>

</html>